package com.zhanggm.s3.user.task;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhanggm.s3.user.entity.User;
import com.zhanggm.s3.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;


@Slf4j
//@Component
public class UserTask {

    @Autowired
    private IUserService userService;

    /**
     * 定时任务SpringTask
     */
//    @Scheduled(fixedDelay = 1000*5)
    @Scheduled(cron = "* */5 * * * *")
    public void checkUser() {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.le(User::getCreatedAt ,DateUtil.offsetDay(new Date(), -30));

        List<User> list = userService.list(queryWrapper);
        list.forEach(item->{
            log.info("用户{}，未登录超过30天，需要重置密码",item.getUsername());
        });

    }

}
